<?php
/*
 * Created on 22.12.2005
 *
 */

class c_urlHandler
{

    var $var;

    function startElement (& $sender, $attrs)
    {
        if (empty($attrs['value']) && empty($attrs['action']))
        {
            die ("Attribute value or action is missing in url tag!\n");
        }
        $attrs['tag'] = 'url';
        if (!empty($attrs['var']))
        {
            $this->var = $attrs['var'];
        }
        else
            unset($this->var); 
        $sender->pushParent($attrs);
        if (!empty($attrs['value']))
        {
            $sender->appendCode('$'."__url = new phpinchains_tagsupport_URL(\$env, ".$attrs['value'].");\n");
        }
        else
        {
            $sender->appendCode('$'."__url = new phpinchains_tagsupport_URL(\$env);\n");
        }
        if (!empty($attrs['action']))
        {
            $sender->appendCode('$'."__url->setAction(".$attrs['action'].");\n");
        }
        if (!empty($attrs['module']))
        {
            $sender->appendCode('$'."__url->setModule(".$attrs['module'].");\n");
        }
        if (!empty($attrs['medium']))
        {
            $sender->appendCode('$'."__url->setMedium(".$attrs['medium'].");\n");
        }
        $env = & env::getInstance();
    }

    function endElement (& $sender)
    {
        $parent = $sender->topParent();
       	$sender->appendCode("\$run = &phpinchains_RuntimeConfig::getInstance();\n");
       	$sender->appendCode("if (\$run->get('sec_code_enabled')) {\n");
       	$sender->appendCode('    $'."__url->addParam('__ss', \$env->getSession('phpinchains_sec_code'));\n");
       	$sender->appendCode("}\n");
       	$sender->appendCode("if (\$run->get('additional_parameters')) {\n");
       	$sender->appendCode('    $'."__url->addParams(\$run->get('additional_parameters'));\n");
       	$sender->appendCode("}\n");
       	if (isset($this->var))
            $sender->appendCode('$actionform->set('.$this->var.', $'."__url->toString());\n");
        else
            $sender->appendCode('$out->write($'."__url->toString());\n");
        $sender->popParent();
    }

}

?>